
#include "StdAfx.h"
#include "BusyWaiter.h"

BusyWaiter::BusyWaiter(){
	wait_time_ = 0;
	wait_count_ = 0;
	wait_remain_ = 0;
}

BusyWaiter::~BusyWaiter(){
}

void BusyWaiter::set( unsigned int wait_time, unsigned int wait_count ){
	wait_time_ = wait_time;
	wait_count_ = wait_count;
	wait_remain_ = wait_count;
}

size_t BusyWaiter::wait(){
	if(! wait_time_ ){
		SLEEP( 0 );
		return 1;
	}

	if(! wait_remain_ )
		return 0;

	if(! wait_time_ )
		return 0;

	SLEEP( wait_time_ );
	wait_remain_--;

	return wait_remain_;
}

void BusyWaiter::reset(){
	wait_remain_ = wait_count_;
}
